     //
//  LoginViewModel.m
//  Rac
//
//  Created by 崔博 on 2018/1/7.
//  Copyright © 2018年 崔博. All rights reserved.
//

#import "LoginViewModel.h"

@implementation LoginViewModel
- (instancetype)init{
    if (self == [super init]) {
        [self setUp];
    }
    return self;
}

- (void)setUp{
    // 处理登录点击的信号
    _loginEnbleSingal = [RACSignal combineLatest:@[RACObserve(self, account),RACObserve(self, pwd)] reduce:^id _Nullable(NSString * account,NSString * pwd){
        return @(account.length && pwd.length);
    }];
    
    // 创建命令
    _loginComand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        //密码加密发
        NSLog(@"准备发送请求%@",input);
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            // 送请求&&获取登录结果
            [subscriber sendNext:@"请求登录的数据"];
            [subscriber sendCompleted];
            return nil;
        }];
    }];
    
    
    
    [_loginComand.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        NSLog(@"我拿到最终的数据了");
    }];
    
    
    // 监听命令的执行过程
    // 菊花的干掉
    [[_loginComand.executing skip:1] subscribeNext:^(NSNumber * _Nullable x) {
        if ([x boolValue]) {
            
        }else{
            
        }
    }];
}
@end
